init = (callBack) => {
  this.callBack = callBack;
};

generatePrimes = (start, range) => {
  let primes = [];
  let isPrime = true;
  let end = start + range;
  for (let i = start; i < end; i++) {
    for (let j = start; j < Math.sqrt(end); j++) {
      if (i !== j && i % j === 0) {
        isPrime = false;
        break;
      }
    }
    if (isPrime) {
      primes.push(i);
    }
    isPrime = true;
  }
  console.log("generatePrimes end");
  this.callBack(`generatePrimes end, start:${start}, range:${range}`);
  return primes;
};

callback = (msg) => {
  console.log("callback:", msg);
};

console.log("---->this is child process:", this);
const min = 2;
const max = 1e7;
init(callback);
const startTime = new Date().getTime();
let rv = generatePrimes(min, max);
const endTime = new Date().getTime();
let costTime = endTime - startTime;
console.log("---->generatePrimes end, costTime:", costTime);
console.log("---->generatePrimes end, rv:", rv);